home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / access next >
Text File  |  1996-11-09  |  1KB  |  68 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/access,v $
  4.  * $Date: 1996/10/30 21:59:01 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: access,v $
  10.  * Revision 1.2  1996/10/30 21:59:01  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:35:27  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: access,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
  19.  
  20. #include <errno.h>
  21.  
  22. #include <unistd.h>
  23. #include <sys/types.h>
  24. #include <sys/os.h>
  25.  
  26. int
  27. access (const char *file, int mode)
  28. {
  29.   int r[6];
  30.   _kernel_oserror *e;
  31.   int i;
  32.   char *f;
  33.  
  34.   f = __uname ((char *)file, 0);
  35.  
  36.   if (e = os_file (0x05, f, r))
  37.     {
  38.       __seterr (e);
  39.       return (-1);
  40.     }
  41.   switch (r[0])
  42.     {
  43.     default:
  44.       errno = ENOENT;
  45.       return (-1);
  46.     case 1:
  47.  
  48.       i = ((r[5] & 0040) >> 4) | ((r[5] & 0020) >> 2) |
  49.     ((r[5] & 0002)) | ((r[5] & 0001) << 2);
  50.  
  51.       if (i & 0002)
  52.     i |= 0001;
  53.  
  54.       if ((i & mode) != mode)
  55.     {
  56.       errno = EPERM;
  57.       return (-1);
  58.     }
  59.  
  60.       return (0);
  61.  
  62.     case 2:
  63.     case 3:
  64.       return (0);
  65.       /* DIR / Image */
  66.     }
  67. }
  68.